package com.xuecheng.swagger.controller;

import com.xuecheng.swagger.domain.Student;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("stu")
@Api(tags = "测试controller",description = "Hello 测试 swagger注解")
public class HelloController {

    /**
     * 测试无参数接口地址
     */
    @ApiOperation("测试方法")
    @GetMapping("hello")
    public String hello() {
        return "hello";
    }

    /**
     * 测试 queryString 风格的参入参数
     */
    @GetMapping
    @ApiOperation("query测试方法")
    @ApiImplicitParam(name = "num",value = "学成的编号",dataType = "String",paramType = "query")
    public Student modifyStudentNum(@RequestParam("num") String num) {
        Student student = new Student(num, "xiaohong", 10, "parts");
        return student;
    }

    /**
     * 测试Restful风格的参入参数
     */
    @GetMapping("{name}")
    public Student modifyStudentName(@PathVariable("name") String name) {
        Student student = new Student("002", name, 10, "parts");
        return student;
    }

    /**
     * 测试json格式的传入参数
     */
    @PostMapping
    public Student modifyStudent(@RequestBody Student student) {
        student.setName("modifyName");
        return student;
    }


    /**
     * 测试 queryString 、Restful 和 json 格式的参数
     */
    @ApiOperation("综合参数方式测试方法")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "学成的编号",required = true,dataType = "String",paramType = "path"),
            @ApiImplicitParam(name = "name",value = "学成的名称",required = true,dataType = "String",paramType = "query")

    })
    @PutMapping("{id}")
    public Student mofidyStudentBynNum(@PathVariable("id") String id, @RequestParam("name") String name, @RequestBody Student student) {
        student.setName(name);
        student.setStuNo(id);
        return student;
    }

}